package com.pzhu.user.service.template.change;

import com.mybatisflex.core.query.QueryCondition;
import com.mybatisflex.core.query.QueryWrapper;
import com.pzhu.base.common.utils.mybatisflex.BaseService;
import com.pzhu.base.common.utils.mybatisflex.QueryUtils;
import com.pzhu.user.domain.entity.ChangeLog;

import java.io.Serializable;

import static com.pzhu.user.domain.entity.table.ChangeLogTableDef.CHANGE_LOG;

public interface ChangeLogService extends BaseService<ChangeLog> {
    /**
     * 通过version 获得最新的变更信息
     */
    default ChangeLog getChangeLogByValueId(ChangeLogType logType, Serializable valueId) {
        QueryCondition condition = QueryUtils.and(
                CHANGE_LOG.VALUE_ID.eq(valueId), CHANGE_LOG.TYPE.eq(logType));
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.and(condition);
        wrapper.orderBy(CHANGE_LOG.VALUE_ID.desc());
        return selectOneByCondition(condition);
    }
}
